package com.example.famhealing.init;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;

import com.example.db.user.user;
import com.example.famhealing.R;
import com.example.famhealing.util.Configuration;

public class LogoActivity extends Activity {
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_logo);
		
        
		Handler handler = new Handler();
		handler.postDelayed(new splashHandler(), 3000);

	}

	class splashHandler implements Runnable {
		public void run() {
			Intent intent;
			user user = new user();
			user.setPhoneNum( getPhoneNumber() );
			user.setDeviceId(getDeviceId());			
			
			Configuration config = Configuration.getInstance(getApplicationContext(), user);
			
			if (config.getUser() == null) {
				intent = new Intent(LogoActivity.this, StartActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
				finish();
			}
			else {
				intent = new Intent(LogoActivity.this, MainMenuActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
				finish();
			}
			
		}
	}
	
	public String getDeviceId()
	{
		TelephonyManager mgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
		return mgr.getDeviceId();
	}
	
	public String getPhoneNumber()
	{
		TelephonyManager mgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
	 	return mgr.getLine1Number();
	}
	

}
